package cake.srcprojector;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;


public abstract class AbstractJSONWriter {

	protected Writer writer = null;
	
	
	public AbstractJSONWriter(OutputStream outputStream) throws IOException {
		this.writer = new OutputStreamWriter(outputStream, "UTF-8");
	}
		
	protected void write(String jsonString) throws IOException {
		this.writer.write(jsonString);
	}	
	
	protected void flush() throws IOException {
		this.writer.flush();
	}	

	
	protected void writeAttribute(String name, String value) throws IOException {
		this.writer.write("\"".concat(name).concat("\":\"").concat(value).concat("\""));
	}
	
	
	protected void writeAttribute(String name, boolean value) throws IOException {
		this.writer.write("\"".concat(name).concat("\":").concat(Boolean.toString(value)));
	}
	
	
	public void start() throws IOException {
		write("[");
	}
	
	public void end() throws IOException {
		write("]");
		this.writer.flush();
		this.writer.close();
	}	
	
	
}
